/**
 * Created by denglingcong on 14-12-16.
 */
define(["app",
        "controllers/common/OrgUserPickerConferenceController"
], function (app) {

    var deps = ["$modal"];

    function orgUserPickerConference($modal) {
        return {
            scope : {
                type : "@",
                title : "@",
                orgType : "@",   /** -1全部，0集团公司，1合作伙伴 **/
                singleOrg : "@",
                singleUser : "@",
                onSelect : "&onSelect",
                companyCode : "@",
            },
            link: function ($scope, elem) {
                elem.on("click", function () {
                    var modalInstance = $modal.open({
                        templateUrl: 'views/common/OrgUserPickerConference.html',
                        controller: "OrgUserPickerConferenceController",
                        backdrop : "static",
                        keyboard: false,
                        resolve : {
                            type : function() {
                                return $scope.type;
                            },
                            title : function(){
                                return $scope.title;
                            },
                            orgType : function(){
                                return $scope.orgType;
                            },
                            singleOrg : function(){
                                return $scope.singleOrg;
                            },
                            singleUser : function(){
                                return $scope.singleUser;
                            },
                            companyCode : function(){
                                return $scope.companyCode;
                            }
                        },
                        windowClass : "orgUserPicker-popup-modal"
                    });

                    modalInstance.result.then(function(users) {
                        $scope.chosenList = [];
                        $scope.data={};
                        if(users==null){
                        	return;
                        }
                        for(var i in users.data){
                            $scope.chosenList.push(users.data[i]);
                        }
                        //$scope.data.time=users.time;
                        $scope.data.list=$scope.chosenList;
                        $scope.data.chooseType=users.chooseType;
                        $scope.data.timeChoose=users.timeChoose;
                        if($scope.onSelect) {
                            $scope.onSelect({$chosenList:$scope.data});
                        }
                        
                        $scope.$emit('confAuthoryAddBroadCastF');
                    });
                });
                
               
                
            }
        };
    }

    orgUserPickerConference.$inject = deps;
    return app.lazy.directive("fcOrgUserPickerConference", orgUserPickerConference);
});